package router

import (
	v1Controller "gintify/api/v1"
	"gintify/middleware"
	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	swaggerFiles "github.com/swaggo/files"
	_ "gintify/docs"
)

//初始化总路由

func InitRouters() *gin.Engine {

	var Router = gin.Default()
	Router.Use(middleware.CorsMiddleware()) // 启用跨域中间件
	c := v1Controller.NewUserController()
	// 实现无需验证的路由
	{
		Router.GET("", func(c *gin.Context) {
			c.String(200, "Hello Golang!\n如果你看到这句话，表示服务已正常启动……")
		})
		Router.POST("/api/v1/register", c.Register)
		Router.POST("/api/v1/login", c.Login)
		Router.POST("/api/v1/logout", middleware.AuthMiddleware(), c.Logout)
		//Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
		url := ginSwagger.URL("/swagger/doc.json")
		Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
	}

	// 方便统一添加路由组前缀 多服务器上线使用
	ApiGroup := Router.Group("/api")

	ApiGroup.Use(middleware.AuthMiddleware()) // 启用用户验证中间件
	ApiGroup.Use(middleware.CasbinHandler()) //启用权限验证中间件

	v1Group := ApiGroup.Group("/v1")
	{
		// 注册系统定义蓝图
		RegisterUserBlueprint(v1Group)    // 注册用户蓝图
		RegisterRoleBlueprint(v1Group)    // 注册角色蓝图
		RegisterApiBlueprint(v1Group)     // 注册资源蓝图
		RegisterMenuRouter(v1Group)       // 注册菜单蓝图
		RegisterCasbinBlueprint(v1Group)  // 注册Casbin蓝图
		RegisterDictionaryRouter(v1Group) // 注册单词本
		RegisterWordRouter(v1Group)       // 注册单词

		// 注册用户自定义蓝图
		RegisterIconBlueprint(v1Group) // 注册图标蓝图
		RegisterBatchRouter(v1Group)   // 批量动作蓝图
		//RegisterBankBlueprint(v1Group)   // 注册题库蓝图
	}

	//v2Group := ApiGroup.Group("/v2")
	//{
	//	RegisterRoleBlueprint(v2Group) // 注册角色蓝图
	//	RegisterUserBlueprint(v2Group) // 注册用户蓝图
	//}

	return Router
}
